var form,$,table,layer,upload,node;
var user = JSON.parse(localStorage.getItem("user"));
var userId = user.userId;
layui.use(['form','jquery','table','layer','upload'],function() {
    form = layui.form;
    $ = layui.jquery;
    table = layui.table;
    layer = layui.layer;
    upload = layui.upload;

    //获取课程数目
    getCourseNums();

    //获取课程列表数据
    getCourseList('','','','');
});

$(".btn").on("click","button",function () {
    $(this).removeClass("layui-btn-primary").siblings("button").addClass("layui-btn-primary");
});
$(".btn").on("mouseover","button",function () {
    $(this).css("border-color","#d2d2d2");
});

//获取商品数目
function getCourseNums(){
    $.ajax({
        url:'/toExamine/getCourseNums',
        type: "post",
        dataType:'json',
        data: {},
        success:function (data) {
            $("#allProductNums").text(data.data.allMicrocircleNums);
            $("#productAdoptNums").text(data.data.microcircleAdoptNums);
            $("#productWaitNums").text(data.data.microcircleWaitNums);
            $("#productNoAdoptNums").text(data.data.microcircleNoAdoptNums);
        }
    });
}
////获取商品列表信息
function getCourseList(result, title, courseName, createName){
    $.ajax({
        url:'/toExamine/getAllCourse',
        type: "post",
        dataType:'json',
        data: {
            "result": result,
            "title": title,
            "courseName": courseName,
            "createName": createName,
        },
        success:function (data) {
            //展示table表格
            showCourseList(data.data);
        }
    });
}

function showCourseList(data) {
    table.render({
        elem: "#demo",
        data: data,
        toolbar:'#toolutil',
        page: true,
        limit: 10,
        cols:[[
            {title:'序号', align:'center',unresize:true, templet:function (data) {
                    return data.LAY_INDEX;
                }},
            {field:'id',title:'课程编号',unresize:true, align:'center'},
            {field:'url',title:'课程图片',align:'center',unresize:true, templet:function(data){
                    return "<img src=' " + data.url  + " '>";
                }},
            {field:'courseName',title:'课程名称',align:'center',unresize:true},
            {field:'courseNprice',title:'价格',align:'center',unresize:true},
            {field:'title',title:'分类',align:'center',unresize:true},
            {field:'createName',title:'上传人员',align:'center',unresize:true},
            {field:'result',title:'审核状态',align:'center',unresize:true, templet:function (data) {
                    if (data.result == 1){
                        return '审核通过';
                    }else if (data.result == 2){
                        return '待审核';
                    }else if (data.result == 3) {
                        return '审核驳回';
                    }
                }},
            {title:'操作',align:'center',unresize:true, templet:function(data){
                    if (data.result == 1){
                        return "<a href='JavaScript:selectCourse(\"" + data.courseId +  "\");' class='operation'>查看</a>";
                    } else if (data.result == 2){
                        return "<a href='JavaScript:selectCourse(\"" + data.courseId +  "\");' class='operation'>查看</a>" + '&nbsp;&nbsp;'
                            +"<a class='operation' href='javascript:judge(\"" + data.toExamineId + "\", \"" + data.courseName + "\", \"" + data.courseId + "\");'>审核</a>";
                    } else if (data.result == 3) {
                        return "<a href='JavaScript:selectCourse(\"" + data.courseId +  "\");' class='operation'>查看</a>";
                    }
                }},
        ]]
    });
}

//查看课程审核
function  selectCourse(courseId) {
    $('#proId').val(courseId);
    layer.open({
        type: 2,
        content: "/toexamine/course/selectCourse.html",
        area: ['1100px','500px'],
        end: function () {

        }
    });
}

//审核
function judge(id, courseName, courseId){
    $('#proId').val(id);
    $('#courseName').val(courseName);
    $('#courseId').val(courseId);
    layer.open({
        type:2,
        area:['540px','350px'],
        content:"/toexamine/course/toExamine.html",
    });
}

//搜索
$("#selCourse").on("click",function () {
    var title = $("input[name=title]").val();
    var courseName = $("input[name=courseName]").val();
    var createName = $("input[name=createName]").val();
    getCourseList('',title,courseName,createName);
});

//高级搜索
function accurate() {
    layer.open({
        type:2,
        content:"/toexamine/course/course-seniorsearch.html",
        area:['470px','380px'],
        end:function () {

        }
    })
}
//刷新
function refresh() {
    location.reload();
}

//返回首页
function backOff(){
    parent.jumpSystemHome();
}